package com.cx.pojo;

import com.cx.service.CallService;
import com.cx.service.NetService;
import com.cx.service.SendService;

/**
 * @author zhangshuai
 * @version V1.0
 * @Project Java2_26
 * @Package com.cx.pojo
 * @Description:
 * @Date 2025/5/20 8:43
 */
// 超级套餐类
public class SupperPackage extends ServicePackage implements CallService, NetService, SendService {

    private static final String packageName = "超人套餐";
    private static final double price = 78.0;
    private Integer talkTime;//通话时长
    private Integer flow;//上网流量
    private Integer smsCount;//短信条数

    //继承父类的构造方法
    public SupperPackage() {
        super("超人套餐", 78);
        this.talkTime = 200;
        this.flow = 5 * 1024;
        this.smsCount = 50;
    }

    @Override
    public void call(int time, MobileCard mobileCard) {


    }

    @Override
    public void net(int flow, MobileCard mobileCard) {

    }

    @Override
    public void send(int count, MobileCard mobileCard) {
        //当前套餐短信条数是50条，超过50条，超出部分每一条0.1元
        //如果实际发送的短信条数小于等于50条，不扣钱，如果大于50条，扣钱
        if (count >= this.smsCount) {
            //超出的短信条数
            int overCount = count - this.smsCount;
            //超出的短信条数乘以0.1元
            double overMoney = overCount * 0.1;
            //扣钱，计算余额
            //判断余额是否足够,如果余额<0.1
            if (mobileCard.getMoney() < 0.1) {
                System.out.println("余额不足，无法发送短信");
                mobileCard.setRealSMSCount(this.smsCount);
            }else if (mobileCard.getMoney() >= 0.1) {
                   //判断剩余的钱能发送多少条短信
                int overSMSCount = (int) (mobileCard.getMoney() / 0.1);

                //如果overSMSCount>overCount  余额足够发送短信
                if (overSMSCount >= overCount) {
                    //扣钱，计算余额
                    mobileCard.setMoney(mobileCard.getMoney() - overMoney);
                    mobileCard.setConsumeAmount(overMoney);
                    //设置实际发送的短信条数
                    mobileCard.setRealSMSCount(this.smsCount + overCount);
                }else if (overSMSCount < overCount) {
                    //扣overSMSCount条短信的钱，计算余额，并提醒用户余额不足
                    mobileCard.setMoney(mobileCard.getMoney() - overSMSCount * 0.1);
                    mobileCard.setConsumeAmount(overSMSCount * 0.1);
                    System.out.println("余额不足，无法发送剩余"+ (overCount- overSMSCount) +"条短信");
                    //设置实际发送的短信条数
                    mobileCard.setRealSMSCount(this.smsCount + overSMSCount);
                }
            }

        }else{
            //设置实际发送的短信条数
            mobileCard.setRealSMSCount(count);
        }
    }

    @Override
    public String toString() {
        return "套餐名称" + packageName
                +"\t套餐价格：" + price
                + "元\t通话时长："
                + talkTime
                + "分钟\t上网流量："
                + flow + "MB\t短信条数："
                + smsCount + "条";
    }
}